package root.electronclass.electronclass.grade.record

import android.os.Bundle
import android.view.View
import root.electronclass.electronclass.common.base.BasicAdapter
import root.electronclass.electronclass.common.base.ViewBindingFragment
import root.electronclass.electronclass.databinding.FragmentClassRecordDetailBinding
import root.electronclass.electronclass.databinding.FragmentClassRecordDetailItemBinding
import root.electronclass.electronclass.grade.model.ClassRecord
import root.electronclass.electronclass.other.PictureActivity

/**
 *
 * @author Lokiy
 * @date 2023/3/17 23:19
 */
class ClassRecordDetailFragment : ViewBindingFragment<FragmentClassRecordDetailBinding>() {

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        val record: ClassRecord = arguments?.getParcelable(EXTRA_DATA) ?: return
        binding.content.text = record.desc
        binding.title.text = record.title
        binding.time.text = record.time
        val adapter = BasicAdapter<String, FragmentClassRecordDetailItemBinding> { holder, item ->
            holder.binding.itemImage.setImageURI(item)
            holder.binding.itemImage.setOnClickListener {
                PictureActivity.startActivity(requireActivity(), ArrayList(list), holder.adapterPosition)
            }
        }
        binding.imageRecycler.adapter = adapter
        adapter.refresh(record.picList?.map { it.url })
    }
}